<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  
  <title>【Docker】--入门使用 | 程序小工  | Just do it!</title>
  <meta name="description" content="遇见更好的自己~" />
  <meta name="keywords" content="" />
  <meta name="HandheldFriendly" content="True" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <link rel="shortcut icon" href="/">
  <link rel="alternate" href="/atom.xml" title="程序小工  | Just do it!">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="在学习Docker的镜像源设置和安装配置后，开始学习Docker的基本使用，包括服务进程的管理，容器、镜像的基本使用和管理。">
<meta name="keywords" content="docker">
<meta property="og:type" content="article">
<meta property="og:title" content="【Docker】--入门使用">
<meta property="og:url" content="http://blog.i2arch.tech/2018/07/31/docker-base/index.html">
<meta property="og:site_name" content="程序小工  | Just do it!">
<meta property="og:description" content="在学习Docker的镜像源设置和安装配置后，开始学习Docker的基本使用，包括服务进程的管理，容器、镜像的基本使用和管理。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-08-14T07:46:10.929Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【Docker】--入门使用">
<meta name="twitter:description" content="在学习Docker的镜像源设置和安装配置后，开始学习Docker的基本使用，包括服务进程的管理，容器、镜像的基本使用和管理。">
    
  <link href="https://fonts.googleapis.com/css?family=Inconsolata|Titillium+Web" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
  <link href='//cdn.bootcss.com/node-waves/0.7.5/waves.min.css' rel='stylesheet'>
  <link rel="stylesheet" href="/style.css">
  <script>
    function setLoadingBarProgress(num) {
      document.getElementById('loading-bar').style.width=num+"%";
    }
  </script>
</head>

<body>
  <div id="loading-bar-wrapper">
  <div id="loading-bar"></div>
</div>


  <script>setLoadingBarProgress(20)</script>
  <header class="l_header">
	<div class='wrapper'>
		<div class="nav-main container container--flex">
			<a class="logo flat-box" href='/' >
				程序小工  | Just do it!
			</a>
			<div class='menu'>
				<ul class='h-list'>
					
						<li>
							<a class='flat-box nav-home' href='/'>
								<i class='icon icon-list2'></i>
								首页
							</a>
						</li>
					
						<li>
							<a class='flat-box nav-archives' href='/archives'>
								<i class='icon icon-bookmark'></i>
								归档
							</a>
						</li>
					
						<li>
							<a class='flat-box nav-about' href='/about'>
								<i class='icon icon-user'></i>
								关于
							</a>
						</li>
					
				</ul>
				<div class='underline'></div>
			</div>
			
				<div class="m_search">
					<form name="searchform" class="form u-search-form">
						<input type="text" class="input u-search-input" placeholder="Search" />
						<span class="icon icon-search"></span>
					</form>
				</div>
			
			<ul class='switcher h-list'>
				
					<li class='s-search'><a href='javascript:void(0)'><span class="icon icon-search flat-box"></span></a></li>
				
				<li class='s-menu'><a href='javascript:void(0)'><span class="icon icon-menu flat-box"></span></a></li>
			</ul>
		</div>

		<div class='nav-sub container container--flex'>
			<a class="logo" class="flat-box" href='javascript:void(0)'>
				Word of Forks
			</a>

			<ul class='switcher h-list'>
				<li class='s-comment'><a href='javascript:void(0)'><span class="icon icon-chat_bubble_outline flat-box"></span></a></li>
				<li class='s-top'><a href='javascript:void(0)'><span class="icon icon-arrow_upward flat-box"></span></a></li>
				<li class='s-toc'><a href='javascript:void(0)'><span class="icon icon-format_list_numbered flat-box"></span></a></li>
			</ul>
		</div>
	</div>
</header>
<aside class="menu-phone">
	<nav>
		
			<a href="/" class="nav-home nav">
				首页
			</a>
		
			<a href="/archives" class="nav-archives nav">
				归档
			</a>
		
			<a href="/about" class="nav-about nav">
				关于
			</a>
		
	</nav>
</aside>

    <script>setLoadingBarProgress(40);</script>
  <div class="l_body">
    <div class='container clearfix'>
      <!-- 左侧内容 -->
      <div class='l_main'>
        <article id="post-docker-base"
  class="post white-box article-type-post"
  itemscope itemprop="blogPost">
	<section class='meta'>

	<h2 class="title">
  	<a href="/2018/07/31/docker-base/">
    	【Docker】--入门使用
    </a>
	</h2>

	<div class="pagenav">
		<time>
			2018-07-31
		</time>

		
    
    <div class='cats'>
        <i class="icon icon-bookmark"></i>
        <a href="/categories/Docker/">Docker</a>
    </div>


		
			<div class="pagetags">
				<i class="icon icon-price-tag" style="margin-right: 2px;"></i>
				
					<a href="/tags/docker/" style="margin-left: 3px;">
						docker
					</a>
				
			</div>
			
	</div>
	</section>

	
	<section class="toc-wrapper"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一-docker使用命令"><span class="toc-text"> 一、Docker使用命令</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1系统管理相关"><span class="toc-text"> 1.系统管理相关</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2docker运行"><span class="toc-text"> 2.Docker运行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3容器的基本使用"><span class="toc-text"> 3.容器的基本使用</span></a></li></ol></li></ol></section>
	

	<section class="article typo">
		<div class="article-entry" itemprop="articleBody">
				<span class="zhaiyao">[摘要]</span>
			<p>在学习Docker的镜像源设置和安装配置后，开始学习Docker的基本使用，包括服务进程的管理，容器、镜像的基本使用和管理。</p>
<a id="more"></a>
<h2 id="一-docker使用命令"><a class="markdownIt-Anchor" href="#一-docker使用命令"></a> 一、Docker使用命令</h2>
<h3 id="1系统管理相关"><a class="markdownIt-Anchor" href="#1系统管理相关"></a> 1.系统管理相关</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看docker运行状态</span></span><br><span class="line">sudo service docker status</span><br><span class="line">sudo systemctl docker status</span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动和停止docker</span></span><br><span class="line">sudo service docker start</span><br><span class="line">sudo systemctl docekr start</span><br><span class="line"></span><br><span class="line">sudo service sdocker stop</span><br><span class="line">sudo systemctl docekr stop</span><br></pre></td></tr></table></figure>
<h3 id="2docker运行"><a class="markdownIt-Anchor" href="#2docker运行"></a> 2.Docker运行</h3>
<p>(1)下载Docker Hub上的&quot;hello-world&quot;镜像[大小只有1.85k]</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo docker run hello-world</span><br></pre></td></tr></table></figure>
<p>(2) 查看docker镜像</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>
<p>(3) 查看docker容器</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看运行状态的container</span></span><br><span class="line">docker ps</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看所有的container</span></span><br><span class="line">docker ps -a</span><br></pre></td></tr></table></figure>
<p>(4)下载<code>ubuntu</code>镜像，创建容器，保持可写入操作，并以bash状态进入容器</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">sudo docker run -i -t ubuntu /bin/bash</span><br><span class="line"><span class="comment"># [-i]: 保证容器中STDIN是开启的，持久的标准写入</span></span><br><span class="line"><span class="comment"># [-t]: 为要创建的容器分配一个伪tty终端，使新创建的容器能够提供一个交互式shell</span></span><br><span class="line"><span class="comment"># [ubuntu]: 使用的镜像名，如果不存在则下载Docker Hub上的镜像</span></span><br><span class="line"><span class="comment"># [/bin/bash]: 让新建的容器运行/bin/bash命令</span></span><br></pre></td></tr></table></figure>
<p>只有指定的/bin/bash命令处于运行状态的时候，容器才处于运行状态，一旦exit退出容器，/bin/bash命令也就结束了，这时容器也随之停止运行。<br>
但容器仍然是存在的。</p>
<p>Docker在文件系统内部用这个镜像创建了一个新容器，该容器拥有自己的网络、IP地址，以及一个用来和宿主机进行通信的桥接网络接口。</p>
<h3 id="3容器的基本使用"><a class="markdownIt-Anchor" href="#3容器的基本使用"></a> 3.容器的基本使用</h3>
<p>(1)查看容器的主机名[即该容器的ID]</p>
<p><code>hostname</code></p>
<p>未完待续！</p>

		</div>

		
			<div class="art-item-footer">
					
						<span class="art-item-left"><i class="icon icon-chevron-thin-left"></i> <a href="/2018/08/07/tp5-controller3/" rel="prev" title="【ThinkPHP5深入理解】控制器（三）-- 前置操作">
							【ThinkPHP5深入理解】控制器（三）-- 前置操作
						</a>上一篇文章</span>
					
					
						<span class="art-item-right">下一篇文章：<a href="/2018/07/31/docker-install/" rel="next"  title="【Docker】--安装与配置">
							【Docker】--安装与配置
						</a><i class="icon icon-chevron-thin-right"></i></span>
					
			</div>
		

		
			

    <div class="recommended_posts">
        <h3>推荐文章</h3>
        <ul>
            
                <li><a href="http://blog.i2arch.tech/2018/08/08/js-react/">【React入门】实现todolist功能</a></li>
            
                <li><a href="http://blog.i2arch.tech/2018/08/07/tp5-controller3/">【ThinkPHP5深入理解】控制器（三）-- 前置操作</a></li>
            
                <li><a href="http://blog.i2arch.tech/2018/07/31/docker-install/">【Docker】--安装与配置</a></li>
            
                <li><a href="http://blog.i2arch.tech/2018/07/31/docker-mirrors/">【Docker】更新docker镜像源</a></li>
            
        </ul>
    </div>


		
	</section>

	

</article>
<script>
	window.subData = {
		title: '【Docker】--入门使用',
		tools: true
	}
</script>

      </div>

      <!-- 右侧边栏组件 -->
      <aside class='l_side'>
        
      </aside>

      <div class="gotop">
          
    <a href='javascript:void(0)'>
        <i class="icon icon-arrow_upward flat-box">
        </i>
    </a>

      </div>
      <script>setLoadingBarProgress(60);</script>
    </div>
  </div>
  <footer id="footer" class="clearfix">

	<div class="social-wrapper">
  	
      
        <a href="https://github.com/zqunor" class="social github"
          target="_blank" rel="external">
          <span class="icon icon-github"></span>
        </a>
      
        <a href="https://www.cnblogs.com/zqunor" class="social zhihu"
          target="_blank" rel="external">
          <span class="icon icon-zhihu"></span>
        </a>
      
        <a href="/atom.xml" class="social rss"
          target="_blank" rel="external">
          <span class="icon icon-rss"></span>
        </a>
      
    
  </div>
  <div>Theme <a href='https://github.com/stkevintan/hexo-theme-material-flow' class="codename">MaterialFlow</a>  Powered by<a href="https://blog.i2arch.tech/" target="_blank">程序小工</a>.</div>

</footer>

  <script>setLoadingBarProgress(80);</script>
  

    <script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src='//cdn.bootcss.com/node-waves/0.7.5/waves.min.js'></script>
    <script src="//cdn.bootcss.com/scrollReveal.js/3.3.2/scrollreveal.min.js"></script>
    <script src="/js/jquery.fitvids.js"></script>
      <script>
        var GOOGLE_CUSTOM_SEARCH_API_KEY = "";
        var GOOGLE_CUSTOM_SEARCH_ENGINE_ID = "";
        var ALGOLIA_API_KEY = "";
        var ALGOLIA_APP_ID = "";
        var ALGOLIA_INDEX_NAME = "";
        var AZURE_SERVICE_NAME = "";
        var AZURE_INDEX_NAME = "";
        var AZURE_QUERY_KEY = "";
        var BAIDU_API_ID = "fca5b83cf69f752ddc96a61ef64a3659";
        var SEARCH_SERVICE = "hexo";
        var ROOT = "/" || "/";
        if (!ROOT.endsWith('/')) ROOT += '/';
      </script>
      <script src="/js/search.js"></script>
        <script src="/js/app.js"></script>
  <script>setLoadingBarProgress(100);</script>
</body>
</html>
